package ac.neec.mio.ui.adapter;

import java.util.List;

import ac.neec.data.RecordDetail;
import ac.neec.mio.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * Created by G011C1093 on 14/01/28.
 */
public class RecordDateAdapter extends ArrayAdapter<RecordDetail> {

	private List<RecordDetail> list;
	private LayoutInflater inflater;
	private TextView dateText;
	private TextView startTimeText;
	private TextView endTimeText;
	private TextView trainingNameText;
	private int item;

	//	private static List<RecordDate> list = SearchResultList.getList();

	public List<RecordDetail> getList() {
		return list;
	}

	public void setItem(int item) {
		this.item = item;
	}

	public int getItem() {
		return item;
	}

	public RecordDateAdapter(Context recordListFragment, int resource, List<RecordDetail> list) {
		super(recordListFragment, resource, list);
		this.inflater = (LayoutInflater) recordListFragment.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.list = list;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.record_list_item, null);
		}
		this.item = position;
		RecordDetail detail = (RecordDetail) getItem(position);
		initFindConvertViews(convertView);

		//TODO
		if (detail.getActivities() != null)
			trainingNameText.setText(detail.getActivities().getDetailJP());
		dateText.setText(detail.getRecordDate().getDate());
		startTimeText.setText(detail.getMeasurementTime());
		endTimeText.setText("");
		return convertView;
	}

	private void initFindConvertViews(View convertView) {
		dateText = (TextView) convertView.findViewById(R.id.text_date);
		startTimeText = (TextView) convertView.findViewById(R.id.text_start_date);
		endTimeText = (TextView) convertView.findViewById(R.id.text_end_date);
		trainingNameText = (TextView) convertView.findViewById(R.id.text_training);

	}

	public int getSize() {
		return list.size();
	}
}
